package com.yxhl.zoume.core.busticket.presenter;

import android.content.Context;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.busticket.view.BannerObtionView;
import com.yxhl.zoume.data.DataConstants;
import com.yxhl.zoume.data.http.model.splashbanner.BannerBean;
import com.yxhl.zoume.data.http.rest.param.base.RequestParamImpl;
import com.yxhl.zoume.data.http.rest.response.splash.BannerResponse;
import com.yxhl.zoume.di.scope.PerActivity;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.splash.BannerUseCase;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by Xboy on 16/3/24.
 */

@PerActivity
public class BusTicketHomePresenter extends BasePresenter  {

    //   private BusTicketHomeView busTicketHomeView;
    private BannerObtionView bannerObtionView;

    // Banner轮播图
    private ConvenientBanner convenientBanner;

     private String[] images = {DataConstants.BUS_TICKET_HOME_BANNER_1, DataConstants.BUS_TICKET_HOME_BANNER_2};
    //  private String[] images = {"http://www.boracaylibrary.com/images/index/index_news01.jpg", "http://www.keyunzhan.com/images/xianlu/20121225/1620145511.jpg"};
    //  List<String> networkImageURLs = Arrays.asList(images);


    @Inject
    BannerUseCase mBannerUseCase;

    @Inject
    public BusTicketHomePresenter(Context context) {
        super(context);
    }

    /**
     * 获取轮播图
     *
     * @param convenientBanner
     */
    public void obtainBanner(ConvenientBanner convenientBanner) {


        mBannerUseCase.execute(new RequestParamImpl(),new ZMSubscriber<BannerResponse>() {
            @Override
            public void onCompleted() {
                super.onCompleted();

            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                bannerObtionView.renderBannerOnError(e.getMessage());
            }

            @Override
            public void onNext(BannerResponse bannerResponse) {
                super.onNext(bannerResponse);
                if (null != bannerResponse) {
                    if (bannerResponse.isSucc()) {
                        List<BannerBean> bannerList = bannerResponse.getBannerList();
                        bannerObtionView.renderBannerOnSuccess(bannerList);
                    } else {
                        bannerObtionView.renderBannerOnFailure(bannerResponse.getResultMessage());
                    }
                } else {
                    bannerObtionView.renderBannerOnFailure(bannerResponse.getResultMessage());
                }
            }
        });
    }


    @Override
    public void attachView(BaseView view) {
        //busTicketHomeView = (BusTicketHomeView) view;
        bannerObtionView = (BannerObtionView) view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mBannerUseCase.unsubscribe();
    }
}
